import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:random_lottery_ticket/dbutil.dart';
import 'random_dialog.dart';
class Records extends StatefulWidget {
  @override
  _RecordsState createState() => _RecordsState();
}


class _RecordsState extends State<Records> {
  List<Map> data;

  void getData () async{
    var lists = await DBUtil.getAllRandomData();
    setState(() {
      data = lists;
    });
  }

  @override
  void initState() {
    getData();
    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    if(data == null){
      return Container(
        child: Text('马上就来...'),
      );
    }else {
      return Container(
        child: ListView.builder(
          itemCount: data.length,
          itemBuilder: (BuildContext ctx, int index) {
            return ListTile(
              title: Text(
                DateTime.fromMicrosecondsSinceEpoch(data[index]['time'])
                    .toString()
                    .substring(0, 19) + "随机数据",
                style: TextStyle(fontSize: ScreenUtil().setSp(60)),),
              trailing: Icon(Icons.keyboard_arrow_right),
              onTap: () {
                var shuju = data[index]['data'].toString().replaceAll(" ", "");
                var datalists = shuju.substring(1, shuju.length - 1).split(",");
                print(datalists.toString());
                if (data[index]['type'] == "0") {
                  showDialog(
                      context: context,
                      builder: (BuildContext context) {
                        return RandomSSQRecordsDialog(datalists);
                      });
                } else {
                  showDialog(
                      context: context,
                      builder: (BuildContext context) {
                        return RandomDLTRecordDialog(datalists);
                      });
                }
              },
            );
          },

        ),
      );
    }
  }
}
